#ifndef __INVERTED_INDEX_DATA_H__
#define __INVERTED_INDEX_DATA_H__

#include <string>
#include "document.h"

namespace invertedindex{

class InvertedIndexData{
	private:
		Word wrd;
		DocumentsContainer dc;
 
	public:
		InvertedIndexData():wrd(0,NULL,0){
		}
	
		InvertedIndexData(unsigned int wordLength,const char* word,unsigned int wordId):
			wrd(wordLength,word,wordId)
		{}
		
		~InvertedIndexData(){
		}
		
		void setWordParameters(unsigned int wordLength,const char* word,unsigned int wordId){
			wrd.setFields( Word( wordLength, word,wordId));
		}
		
		
		void setWord(const Word& wr){
			wrd.setFields(wr);
		}
		
		Word* getWordObject()const{
			return wrd.duplicate();
		}

		unsigned int getWordId()const{
			return wrd.getWordId();
		}
		unsigned int getWordLength()const {
			return wrd.getWordLength(); 
		}
		std::pair<unsigned int,char*> getWord()const{
			return wrd.getWord();
		}
		
		void setWordId(unsigned int wordId){
			wrd.setWordId(wordId);
		}


		int comparate(const InvertedIndexData& iid)const {
			int ret=wrd.comparate(iid.wrd);
			return ret;
		}

		bool operator ==(const InvertedIndexData& iid)const{
			bool ret=false;
			int reto=wrd.comparate(iid.wrd);
			if((reto==0)&&(dc==iid.dc))
				ret=true;
			return ret;
		}
		
		
		void setFields(const InvertedIndexData& iid){
			(this->dc).setFields(iid.dc);
			(this->wrd).setFields(iid.wrd);
		}
		
		bool insertDocument(const Document& document){
			return dc.insertDocument(document);
		}
		
		bool removeDocument(const Document& document){
			return dc.removeDocument(document);
		}
		
		unsigned int getDocumentsCount()const{
			return dc.getDocumentCount(); 
		}
				
		std::pair<bool, Document*> getDocument(unsigned int index) const{
			return dc.getDocument(index);
		}
		
		
		std::pair<bool, unsigned int> getIdOfDocument(unsigned int documentIndex) const{
			return dc.getIdOfDocument(documentIndex);
		}
		
		std::pair<bool, unsigned int> getNumberOfOccurrencesInDocument(unsigned int documentIndex) const{
			return dc.getNumberOfOccurrencesInDocument(documentIndex);
		}
		
		std::pair<bool, unsigned int> getOccurrenceInDocument(unsigned int documentIndex, unsigned int occurranceIndex) const{
			return dc.getOccurrenceInDocument(documentIndex, occurranceIndex);
		}
		
		std::ostream& toOstream(std::ostream& out)const{
			out<<"   Inverted Index Data: "<<std::endl;
			wrd.toOstream(out);
			dc.toOstream(out);
			return out;
		}
		
		
		friend class InvertedIndex;
};


}

#endif

